﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AiXiu.IBLL;
using AiXiu.Model;
using AiXiu.IDAL;
using AiXiu.DAL;
using AiXiu.Common;

namespace AiXiu.BLL
{
    /// <summary>
    /// 用户信息处理类
    /// </summary>
    public class UserManager : IUserManager
    {
        IUserService userservice = new UserService();

        /// <summary>
        /// 根据用户Id获取到用户的信息
        /// </summary>
        /// <param name="Id">用户Id</param>
        /// <returns>用户Id对应的用户信息</returns>
        public TBUsers getUserById(int Id)
        {
            return new UserService().getUserById(Id);
        }

        public OperResult editUserInfo(TBUsers newUser)
        {
            try
            {
                if (userservice.editUserInfo(newUser) > 0)
                {
                    return OperResult.Succeed();
                }
                else
                {
                    return OperResult.Failed("未知错误：修改失败！");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex + " --修改用户信息");
                return OperResult.Wrong(ex, ex.Message);
            }
        }

        public OperResult editAvatar(TBUsers newUser)
        {
            try
            {
                if (userservice.editAvatar(newUser) > 0)
                {
                    return OperResult.Succeed();
                }
                else
                {
                    return OperResult.Failed("未知错误：修改失败！");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex + " --修改用户头像");
                return OperResult.Wrong(ex, ex.Message);
            }
        }
    }
}
